﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionDates.aspx.cs" Inherits="TheatreStaff_SessionDates" %>
<%@ Register TagPrefix="custom" Namespace="myControls" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript">

    function displayCalendar() {
        var datePicker = document.getElementById('datePicker');
        datePicker.style.display = 'block';
    }
</script>
<script runat ="server" >
    protected void Clear(object sender, EventArgs e)
    {
        GridViewRow row = grdSession.SelectedRow;
        Label7.Text = row.Cells[3].Text;
        Label15.Text = string.Empty;
        Label16.Text = string.Empty;
    }

    protected void Cancel(object sender, EventArgs e)
    {
       
        //txtDateI.Text = string.Empty;
        //ddlMovieTitleI.SelectedIndex = -1;
        //ddlscheduleI.SelectedIndex = -1;
        //ddlSessionI.SelectedItem.Text = "Select";
        //ddlTypeI.SelectedIndex = -1;
        //ddlCinema.SelectedIndex = -1;
        Label15.Text = string.Empty;
        Label16.Text = string.Empty;
        grdSession.DataBind();
    }

    //protected void Insert(object sender, EventArgs e)
    //{
    //    Label15.Text = string.Empty;
    //    Label16.Text = string.Empty;
    //    string connectionString;
    //    connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    //    SqlConnection con = new SqlConnection(connectionString);
    //    SqlConnection con1 = new SqlConnection(connectionString);
    //    SqlCommand cmd1 = new SqlCommand("INSERT datesession(date,sessionid,movieid,sessiontype,scheduleid) values (@date,@sessionid,@movieid,@sessiontype,@scheduleid)", con1);
    //    SqlCommand cmd = new SqlCommand("SELECT datesession.date,datesession.sessionid from datesession,Movie,TheatreStaff WHERE TheatreStaff.TheatreId=Movie.TheatreId AND datesession.movieid=Movie.MovieId AND Movie.TheatreId=@TheatreId AND datesession.date=@date AND datesession.sessionid=@sessionid", con);
    //    string ParamString = lblId.Text;
    //    Int32 RowCount;
    //    Boolean HasMovies;

    //    cmd.Parameters.AddWithValue("@TheatreId", ParamString);
    //    cmd.Parameters.AddWithValue("@date", txtDateI.Text );
    //    cmd.Parameters.AddWithValue("@sessionid", ddlSessionI.SelectedValue);
    //    //cmd.Parameters.AddWithValue("@movieid", ddlMovieTitleI.SelectedValue );

    //    using (con)
    //    {
    //        con.Open();
    //        SqlDataReader Reader = cmd.ExecuteReader();

    //        if (Reader.HasRows)
    //        {
                
    //            Label15.Text = "The session date " + txtDateI.Text + " already exist in the database!";
                
    //            //lblCheck.Text = string.Empty;
    //            //ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "Focus", "<script language='JavaScript' 'showInsert();'/>");

    //            HasMovies = true;

    //        }
    //        else
    //        {
    //            HasMovies = false;

    //        }
    //    }
    //    using (con1)
    //    {
    //        con1.Open();
    //        if (HasMovies == false)
    //        {
    //            cmd1.Parameters.AddWithValue("@date", txtDateI.Text);
    //            cmd1.Parameters.AddWithValue("@sessionid", ddlSessionI.SelectedValue );
    //            cmd1.Parameters.AddWithValue("@movieid", ddlMovieTitleI.SelectedValue );
    //            cmd1.Parameters.AddWithValue("@sessiontype", ddlTypeI.SelectedValue );
    //            cmd1.Parameters.AddWithValue("@scheduleid", ddlscheduleI.SelectedValue );
    //            RowCount = cmd1.ExecuteNonQuery();
    //            txtDateI .Text  = string.Empty;
    //            ddlMovieTitleI.SelectedIndex = -1;
    //            ddlscheduleI.SelectedIndex = -1;
    //            //ddlSessionI.SelectedItem.Text = "Select";
    //            ddlTypeI.SelectedIndex = -1;
    //            ddlCinema.SelectedIndex = -1;
    //            //if (RowCount > 0)
    //            //{
    //            Label16.Text  = "The session " + txtDateI.Text  + " has been added sucessfully!";
                

    //            //}
    //        }

    //    }
    //    grdSession.DataBind();
    //}
    void Page_Load()
    {
        if (!Page.IsPostBack)
            grdSession.SelectedIndex = 0;
        Label15.Text = string.Empty;
        Label16.Text = string.Empty;
    }
    protected void OnItemInserted_Click(object sender, DetailsViewInsertedEventArgs e)
    {
        grdSession.DataBind();
        Label15.Text = string.Empty;
        Label16.Text = string.Empty;
    }
    protected void OnItemUpdated_Click(object sender, DetailsViewUpdatedEventArgs e)
    {
        grdSession.DataBind();
        Label15.Text = string.Empty;
        Label16.Text = string.Empty;
    }
    protected void function1(object sender, EventArgs e)
    {
        DropDownList tb = (DropDownList)dtlSpecial.FindControl("ddlSession");
        Label3.Text = tb.SelectedItem.Value;
    }
    protected void function2(object sender, EventArgs e)
    {
        DropDownList tb1 = (DropDownList)dtlSpecial.FindControl("ddlMovieTitle");
        Label4.Text = tb1.SelectedItem.Text;
    }
    
       protected void function3(object sender, EventArgs e)
    {
        TextBox tb2 = (TextBox)dtlSpecial.FindControl("txtSessionDate");
        Label6.Text = tb2.Text;
    } 
    
       protected void function4(object sender, EventArgs e)
    {
        DropDownList tb3= (DropDownList)dtlSpecial.FindControl("ddlType");
     

    }

       protected void function6(object sender, EventArgs e)
       {
         GridViewRow row= grdSession.SelectedRow;
         Label7.Text = row.Cells[2].Text;
       }
    
       protected void function5(object source, ServerValidateEventArgs args)
       {
           DropDownList tb = (DropDownList)dtlSpecial.FindControl("ddlSession");
           DropDownList tb1 = (DropDownList)dtlSpecial.FindControl("ddlMovieTitle");
           TextBox tb2 = (TextBox)dtlSpecial.FindControl("txtSessionDate");
           DropDownList tb3 = (DropDownList)dtlSpecial.FindControl("ddlType");
     
           if ((Label3.Text == tb.SelectedItem.Value) && (Label6.Text == tb2.Text))
           {
               args.IsValid = true;
               Label8.Text = "same";
           }

           else
           {
            
               string connectionString;
               connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
               SqlConnection con = new SqlConnection(connectionString);
               SqlCommand cmd = new SqlCommand("SELECT datesession.date,datesession.sessionid from datesession,Movie,TheatreStaff WHERE   datesession.date=@date AND datesession.sessionid=@sessionid", con);
               string ParamString = lblId.Text;

         
               cmd.Parameters.AddWithValue("@date", DateTime.Parse(tb2.Text));
               cmd.Parameters.AddWithValue("@sessionid", tb.SelectedItem.Value);
               //cmd.Parameters.AddWithValue("@movieid", ddlMovieTitleI.SelectedValue );

               using (con)
               {
                   con.Open();
                   SqlDataReader Reader = cmd.ExecuteReader();

                   if (Reader.HasRows)
                   {
                       args.IsValid = false;
                       Label8.Text = " different";

                   }
                   else
                   {

                       args.IsValid = true;
                       Label8.Text = " new";
                   }
               }
           }
       }
</script>
<script type="text/javascript">
    function showInsert() {
        var divInsert = document.getElementById('divInsert');
        divInsert.style.display = 'block';
    }
    function MM_preloadImages() { //v3.0
        var d = document; if (d.images) {
            if (!d.MM_p) d.MM_p = new Array();
            var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
                if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
        }
    }
    function MM_findObj(n, d) { //v4.01
        var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
            d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
        }
        if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
        for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
        if (!x && d.getElementById) x = d.getElementById(n); return x;
    }
    function MM_swapImage() { //v3.0
        var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
            if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }
    function MM_swapImgRestore() { //v3.0
        var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
    }
</script>
 <style type="text/css">
        #datePicker
        {
            display:none;
            position:absolute;
            border:solid 2px black;
            background-color:white;
           
        }
    
    </style>
<style type="text/css">
#divDisplay
{
    border:solid 1px White;
    width:400px;
    padding:15px;
    margin:0px auto;
    text-align:center;
    border:1px solid #333;
}
.center1
{
    padding-left:320px;
}
.C
{
    color:Green ;
    font-size:larger;
    font-weight :bolder ;
}
.I
{
    color:Maroon ;
    font-size:larger;
    font-weight :bolder ;
}
#divInsert
{
    display:none;
    border:solid 1px black;
    width:500px;
    position:absolute;
    top:200px;
    left:100px;
    padding:10px;
    background-color:Silver;
    color:Black ;
}
html
{
  background-image:url('image/back.jpg'); 

    padding:10px;
    color:White;    
  
}
.content1
{
    margin:auto;
    width:850px;
}
.column
{
    float:left;
    width:348px;
}
.selectedRow
{
    background-color:Gray;
}

.content
{
    width:950px;
    margin:auto;
        height: 197px;
}

.link
{
  margin-left:350px; 
     font-weight:bold;
  font-size:large;  
    font-size:x-large;
}
.link2
{
  margin-left:50px; 
     font-weight:bold;
  font-size:large;  
    font-size:x-large;
}
a
{
 color: white;
 text-decoration:underline;
 font-weight:bold;

}
a:hover
{
 color: red; 
  text-decoration:none;
  font-weight:bold;

}
.join
{
   background-color:#0099FF;
  clip:auto;
  font-weight:bold;
  font-size:large;
}
.table2
{
 border-style:solid;
   border-color:Black;
   background-color:White;
   color:Black;  
   width:900px; 
}
.row
{
   background-color:Gray;
   color:White;
}
.ticket
{
   background-color:#CC0000;
color:White;

}

.ticket:hover
{
 color: black; 
  text-decoration:none;


}
    .style1
    {
        width: 509px;
    }
    
.footer
{

     font-weight:bold;
  font-size:large;  

}
.ticket1
{
    padding-left:200px;
}
.view2
{
 padding-left:180px;  
}
.text
{
 font-weight:bold;
}
.button
{
 margin-left:250px;
}
.view3
{
    padding-left:120px;
}
.footer
{

   margin-top:250px;
}
.center
{
    padding-left:360px;
}
.cinema
{
    padding-left:590px;
}
     .menu
{
 padding-left:150px;  

}
     .sessionDateList:hover
{
 color: White; background-color:rgba(255,0,0,.75);
}
</style>
    <title>Session Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="content">
 <asp:Image ID="Image1" Width="1000" Height="130" ImageUrl="~/image/tdk-jun5-bannerbatmanexclusivo2.jpg" runat="server" /><br />
<asp:HyperLink ID="HyperLink14"  CssClass="link" NavigateUrl="~/Default.aspx" runat="server">Home</asp:HyperLink>
<asp:HyperLink ID="HyperLink1"  CssClass="link2" NavigateUrl="~/Session.aspx" runat="server">Session</asp:HyperLink> <asp:HyperLink ID="HyperLink2" CssClass="link2" NavigateUrl="~/Movie.aspx" runat="server">Movies</asp:HyperLink>
<asp:HyperLink ID="HyperLink3" CssClass="link2"  NavigateUrl="~/Price.aspx" runat="server">Prices</asp:HyperLink>

<br /> <br />
   <%--<asp:Label ID="Label05" runat="server"  Text="Theatre" CssClass="cinema" Font-Bold="True" Font-Underline="True"></asp:Label>
        <asp:Label ID="Label5" runat="server"  ForeColor="Yellow"></asp:Label>
      
&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp 
          <asp:Label ID="Label10" runat="server" Text="UserName" Font-Bold="True"></asp:Label>    <asp:LoginName ID="LoginName1" runat="server" /> 
    &nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp<asp:LoginStatus ID="LoginStatus1" runat="server" ForeColor="#99CCFF" />--%>
<table class="center1" >
        <tr>
            <td>
               <asp:Label ID="Label22222" runat="server" CssClass="menu"  Text="Theatre" Font-Bold="True" Font-Underline="True"></asp:Label>  
            </td>
            <td>
                 <asp:Label ID="Label5" runat="server"  ForeColor="Yellow"></asp:Label>
                 &nbsp;&nbsp;
            </td>
       <%-- </tr>
 </table> --%>
    <%--<td>&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp</td>--%>
<%--&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp --%>
  <%--<table align="center" >
        <tr>--%>
            <td>
                <asp:Label ID="Label12" runat="server" Text="UserName" Font-Bold="True"></asp:Label>
                &nbsp;&nbsp;&nbsp;
            </td>
            <td>
                <asp:LoginName ID="LoginName1" runat="server" /> 
                &nbsp;&nbsp;&nbsp;
            </td>
            <td>
                 <asp:LoginStatus ID="LoginStatus1" runat="server" ForeColor="#99CCFF" />
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
        </tr>
    </table>
        <hr />
  <asp:Label ID="Label9" runat="server" Text="Maintain:" Font-Bold="True" Font-Size="Larger" Font-Underline="True"></asp:Label>
<asp:HyperLink ID="HyperLink4" runat="server" 
            NavigateUrl="~/TheatreStaff/Cinema.aspx" ForeColor="#FFCC99">[Cinemas]</asp:HyperLink>&nbsp;&nbsp;
    <asp:HyperLink ID="HyperLink5" runat="server"  ForeColor="#FFFF99" NavigateUrl="~/TheatreStaff/Movies.aspx">[Movies]</asp:HyperLink> &nbsp;
    <asp:HyperLink ID="HyperLink144" runat="server" NavigateUrl="~/TheatreStaff/Schedule.aspx" ForeColor="#FF9900">[Schedules]</asp:HyperLink>&nbsp;   
 <asp:HyperLink ID="HyperLink117" runat="server" NavigateUrl="~/TheatreStaff/Session.aspx" ForeColor="#FF6699">[Session Times]</asp:HyperLink>&nbsp;  
  <asp:HyperLink ID="HyperLink116" runat="server" NavigateUrl="~/TheatreStaff/SessionDates.aspx" ForeColor="#66FF66">[Session Date]</asp:HyperLink>&nbsp;   
 <asp:HyperLink ID="HyperLink115" runat="server" NavigateUrl="~/TheatreStaff/SpecialTickets.aspx" ForeColor="Aqua">[Specail Price]</asp:HyperLink>&nbsp;
 <asp:HyperLink ID="HyperLink107" runat="server" NavigateUrl="~/TheatreStaff/specialday.aspx" ForeColor="#CCFF33">[Special Ticket Pricing Days]</asp:HyperLink>&nbsp;  
     <asp:HyperLink ID="HyperLink6" runat="server" NavigateUrl="~/TheatreStaff/SalesReports.aspx" ForeColor="#CCFFFF">[Sales Report]</asp:HyperLink>&nbsp;
             <asp:HyperLink ID="HyperLink11" runat="server" NavigateUrl="~/TheatreStaff/AddNewUser.aspx" ForeColor="#66FF99">[Add New User]</asp:HyperLink>&nbsp;
  <hr />
            <h3><asp:Label ID="Label2" Text ="Session Dates Maintenance" runat="server" CssClass="center" ForeColor="#66FF66" /></h3>   
    

                
              <asp:BulletedList ID="BulletedList2"  CssClass="bullet" ForeColor="white" runat="server">
               <%--<asp:ListItem  Text="When you insert the release date, please folow the format: dd/mm/yyyy" />--%>
               <asp:ListItem Text="Click 'Select' to view more details" />
               <asp:ListItem Text="Click 'Edit' to view the update screen to update session date details. You can not edit a session date to another sessiondate which already exist." />
               <asp:ListItem Text="Click 'Cancel' to return to the Movie Session Date Maintenance section" />
               <asp:ListItem Text="Click 'Delete' to delete a session date , when you do not see 'Delete' that means the tickets are sold and you can not delete that session date" />
               <asp:ListItem Text="Click 'Insert Session Date' to insert a new session Date. You can not insert a sessiondate which already exist" />
       
        </asp:BulletedList>
       
        </asp:BulletedList> 
     <asp:ScriptManager
        id="sm1"
        Runat="server" /> 
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <ContentTemplate>
     <div class ="content1">
       
        <asp:Label ID="lblId" runat="server" Visible="false" ></asp:Label>
         <table  >
            <tr>
                <td> <h3><asp:Label ID="Label1" Text ="Maintain Movie Sesssions Dates" Visible="false"  runat="server" /></h3></td>
            </tr>
         </table>
         
            <div class="column">
             <asp:Label ID="Label15" CssClass="I" runat="server"  Text="" ></asp:Label> 
                    <%--<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>--%>
                    <%--<asp:RequiredFieldValidator ID="reqError" runat="server" ControlToValidate="lblError" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>--%>
                    
             <asp:Label ID="Label16" CssClass="C" runat="server" Text=""></asp:Label>
          
            <asp:GridView ID="grdSession"
            AllowPaging="True" DataSourceID ="srcgrdSession"    SelectedRowStyle-CssClass="selectedRow" 
            AutoGenerateSelectButton ="True" OnSelectedIndexChanged ="Clear"
            DataKeyNames ="datesessionid" AutoGenerateColumns ="False" runat="server"  RowStyle-CssClass="sessionDateList"
                 Height="360px" Width="16px">
                <Columns >
                   
                                   <custom:DeleteButtonField CommandName="Delete" ConfirmText ="Are you sure that you want to delete this record?" />
                   <asp:BoundField DataField="time"   HeaderText ="Session Time" />
                    <asp:BoundField DataField ="cinema" HeaderText ="Cinema Id" />
                    <asp:BoundField DataField ="MovieTitle" HeaderText ="Movie Title" />
                    <asp:BoundField DataField ="date" HeaderText ="Date" DataFormatString ="{0:d}" />
                    <%--<asp:BoundField DataField ="time" HeaderText ="Session Time" DataFormatString ="{0:t}" />--%>

                </Columns>
            </asp:GridView>
            <asp:HyperLink ID="HyperLink17" NavigateUrl ="~/TheatreStaff/InsertSessionDates.aspx" runat="server">Insert Session Dates</asp:HyperLink>
           </div>
         
         <div class="column">
             <asp:Label ID="Label3" runat="server"  Visible="false"></asp:Label>
             <asp:Label ID="Label4" runat="server" Visible="false"></asp:Label>
             <asp:Label ID="Label6" runat="server" Visible="false"></asp:Label>
             <asp:Label ID="Label7" runat="server"  Visible="false"></asp:Label>
             <asp:Label ID="Label8" runat="server" Visible="false"></asp:Label>
               <asp:DetailsView ID="dtlSpecial" 
               AutoGenerateEditButton ="True" AutoGenerateInsertButton ="false"
                 OnItemInserted ="OnItemInserted_Click" OnItemUpdated ="OnItemUpdated_Click"   
               AutoGenerateRows ="False" runat="server"  DataKeyNames ="datesessionid"  RowStyle-CssClass="sessionDateList"
                 DataSourceID ="srcSessionSelect">
                <Fields >
                     <asp:TemplateField HeaderText ="Session ID" HeaderStyle-Font-Bold="true">
                        <ItemTemplate>
                            <%# Eval("time")%> 
                        </ItemTemplate>
                        <EditItemTemplate >
                           
                            <asp:DropDownList 
                                    ID="ddlSession" 
                                     DataSourceID ="srcSessionid" 
                                     DataTextField ="time"
                                     DataValueField ="sessionid"
                                     SelectedValue='<%# Bind("sessionid") %>'
                                     runat="server" AppendDataBoundItems ="true" OnDataBound="function1">
                                  <asp:ListItem Text ="Select" Value ="-1" />
                                    </asp:DropDownList> 
                                     <asp:CustomValidator ID="CustomValidator1" ControlToValidate="ddlSession" OnServerValidate="function5" runat="server" ErrorMessage="This time of this date is booked,please try another! "></asp:CustomValidator>
                                <asp:RequiredFieldValidator
                                    id="reqSession"
                                    ControlToValidate="ddlSession"
                                    InitialValue ="-1" 
                                    Text="(Required)"
                                    Runat="server" />
                        </EditItemTemplate>

<HeaderStyle Font-Bold="True"></HeaderStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText ="Movie Title" HeaderStyle-Font-Bold="true">
                        <ItemTemplate>
                            <%# Eval("MovieTitle")%> 
                        </ItemTemplate>
                        <EditItemTemplate >
                            <asp:DropDownList 
                                    ID="ddlMovieTitle" 
                                     DataSourceID ="srcMovie" 
                                     DataTextField ="MovieTitle"
                                     DataValueField ="MovieId"
                                     SelectedValue='<%# Bind("movieid") %>'
                                     runat="server" AppendDataBoundItems ="true" OnDataBound="function2">
                                     <asp:ListItem Text ="Select" Value ="-1"   />
                                    </asp:DropDownList> 
                                <asp:RequiredFieldValidator
                                    id="reqMovie"
                                    ControlToValidate="ddlMovieTitle"
                                    InitialValue ="-1" 
                                    Text="(Required)"
                                    Runat="server" />
                        </EditItemTemplate>

<HeaderStyle Font-Bold="True"></HeaderStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText ="Session Date" HeaderStyle-Font-Bold="true">
                        <ItemTemplate>
                            <%# Eval("date", "{0:dd/MM/yyyy}")%> 
                        </ItemTemplate>
                        <EditItemTemplate>
                                  <asp:TextBox
                                    id="txtSessionDate"
                                    Text='<%# Bind("date","{0:dd/MM/yyyy}") %>'
                                    Runat="server" OnPreRender="function3" />
                                  <asp:RequiredFieldValidator
                                    id="reqDate"
                                    ControlToValidate="txtSessionDate"
                                    Text="(Required)"
                                    Runat="server" />
                               <asp:RegularExpressionValidator 
                     ID="RegularExpressionValidator2I" 
                     ControlToValidate="txtSessionDate" 
                     runat="server" 
                     ErrorMessage="(Please enter a valid date in the dd/MM/yyyy format)"
                      ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d">
                      </asp:RegularExpressionValidator> 
                                    
                        </EditItemTemplate>
                        
<%--<HeaderStyle Font-Bold="True"></HeaderStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText ="Cinema:" HeaderStyle-Font-Bold="true">
                        <ItemTemplate>
                             <%# Eval("cinema")%> 
                        </ItemTemplate>
                        <EditItemTemplate>
                                  <asp:DropDownList 
                                    ID="ddlcinema" 
                                     DataSourceID ="srcCinema" 
                                     DataTextField ="cinemaid"
                                     DataValueField ="cinemaid"  
                                     SelectedValue='<%# Bind("cinema") %>'
                                     runat="server" AppendDataBoundItems ="true"  >
                                     <asp:ListItem Text ="Select" Value ="-1"  />
                                    </asp:DropDownList> 
                        </EditItemTemplate>--%>
                        
<%--<HeaderStyle Font-Bold="True"></HeaderStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText ="Session Type" HeaderStyle-Font-Bold="true">
                        <ItemTemplate>
                            <%# Eval("sessiontype")%> 
                        </ItemTemplate>
                        <EditItemTemplate >
                            <asp:DropDownList 
                                    ID="ddlType" 
                                     DataSourceID ="srcType" 
                                     DataTextField ="sessiontype"
                                     DataValueField ="sessiontype"  
                                     SelectedValue='<%# Bind("sessiontype") %>'
                                     runat="server" AppendDataBoundItems ="true"  OnDataBound="function4">
                                     <asp:ListItem Text ="Select" Value ="-1"  />
                                    </asp:DropDownList> 
                                <asp:RequiredFieldValidator
                                    id="reqsessiontype"
                                    ControlToValidate="ddlType"
                                    InitialValue ="-1" 
                                    Text="(Required)"
                                    Runat="server" />
                        </EditItemTemplate>--%>

<HeaderStyle Font-Bold="True"></HeaderStyle>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText ="Schedule Start Date" HeaderStyle-Font-Bold="true">
                        <ItemTemplate>
                            <%# Eval("ScheduleStartDate", "{0:d}")%> 
                        </ItemTemplate>
                         <EditItemTemplate >
                            <asp:DropDownList 
                            ID="ddlschedule" 
                             DataSourceID ="srcSchedule" 
                             DataTextField ="ScheduleStartDate" DataTextFormatString="{0:dd/MM/yyyy}"
                             DataValueField ="ScheduleId"  
                             SelectedValue='<%# Bind("scheduleid") %>'
                             runat="server" AppendDataBoundItems ="true" >
                             <asp:ListItem Text ="Select" Value ="-1" />
                            </asp:DropDownList> 
                            <asp:RequiredFieldValidator
                                id="reqSchedule"
                                ControlToValidate="ddlSchedule"
                                InitialValue ="-1" 
                                Text="(Required)"
                                Runat="server" />
                        </EditItemTemplate>

<HeaderStyle Font-Bold="True"></HeaderStyle>
                    </asp:TemplateField>
                  </Fields>
               </asp:DetailsView>
           </div> 
                 
    </div>
     </ContentTemplate>
         </asp:UpdatePanel> 
  <%--  <div id="divInsert">
      <asp:UpdatePanel
                    id="up1"
                    Runat="server">
                     <ContentTemplate>
        <fieldset >
            <legend >Insert Session Dates</legend>
            <table>
                
                <tr>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="Date"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtDateI" runat="server"></asp:TextBox>
                </td>
                <td>
                     <asp:RequiredFieldValidator
                    id="reqDateI"
                    ControlToValidate="txtDateI"
                    Text="(Required)"
                    Runat="server" />
                </td>
                <td>
                    <asp:CompareValidator ID="cmpDateI" ControlToValidate ="txtDateI" runat="server" 
                    ErrorMessage="(Please enter a valid date in the mm/dd/yyyy format)" 
                    Operator="DataTypeCheck" Type="Date">
                    </asp:CompareValidator>   
                </td>
                </tr>
                <tr>
                <td>
                    <asp:Label ID="Label4" runat="server" Text="Movie Title"></asp:Label>
                </td>
                <td>
                     <asp:DropDownList 
                    ID="ddlMovieTitleI" 
                     DataSourceID ="srcMovie" 
                     DataTextField ="MovieTitle"
                     DataValueField ="MovieId"
                     runat="server" AppendDataBoundItems ="true" >
                     <asp:ListItem Text ="Select" Value ="-1" />
                    </asp:DropDownList> 
                </td>
                <td>
                <asp:RequiredFieldValidator
                    id="reqMovieI"
                    ControlToValidate="ddlMovieTitleI"
                    InitialValue ="-1" 
                    Text="(Required)"
                    Runat="server" />
                </td>
                </tr> 
             
                <tr>
                
                <td>
                <asp:Label ID="Label9" runat="server" Text="Cinema"></asp:Label>
                </td>
                <td>
                 
                   
                    <asp:DropDownList 
                    ID="ddlCinema" 
                     DataSourceID ="srcCinema" 
                     DataTextField ="CinemaId"
                     DataValueField ="CinemaId" 
                      AutoPostBack="true" 
                     runat="server" AppendDataBoundItems ="true" >
                     <asp:ListItem Text ="Select" Value ="-1" />
                    </asp:DropDownList>
                  
                 </td>
                 <td> 
                    <asp:RequiredFieldValidator
                    id="RequiredFieldValidator1"
                    ControlToValidate="ddlCinema"
                    InitialValue ="-1" 
                    Text="(Required)"
                    Runat="server" />
                </td>
                </tr>
                <tr>
                <td>
                <asp:Label ID="Label6" runat="server" Text="Session Time"></asp:Label>
                </td>
                <td>
                    
                    <asp:DropDownList 
                    ID="ddlSessionI" 
                     DataSourceID ="srcSessionid" 
                     DataTextField ="time"
                     DataValueField ="sessionid"
                     runat="server"  >
                     <asp:ListItem Text ="Select" Value ="-1" />
                    </asp:DropDownList>
                   
                 </td>
                 <td> 
                    <asp:RequiredFieldValidator
                    id="reqSessionI"
                    ControlToValidate="ddlSessionI"
                    InitialValue ="-1" 
                    Text="(Required)"
                    Runat="server" />
                </td>
                </tr>
               
                <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="Session Type"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList 
                    ID="ddlTypeI" 
                     DataSourceID ="srcType" 
                     DataTextField ="sessiontype"
                     DataValueField ="sessiontype"
                     runat="server" AppendDataBoundItems ="true" >
                     <asp:ListItem Text ="Select" Value ="-1" />
                    </asp:DropDownList> 
                </td>
                <td>
                    <asp:RequiredFieldValidator
                    id="reqsessiontypeI"
                    ControlToValidate="ddlTypeI"
                    InitialValue ="-1" 
                    Text="(Required)"
                    Runat="server" />
                </td>
                </tr>
                <tr>
                <td>
                    <asp:Label ID="Label8" runat="server" Text="Schedule Start Date"></asp:Label>
                </td>
                <td>
                     <asp:DropDownList 
                    ID="ddlscheduleI" 
                     DataSourceID ="srcSchedule" 
                     DataTextField ="ScheduleStartDate"
                     DataValueField ="ScheduleId" DataTextFormatString ="{0:dd/MM/yyyy}"
                     runat="server" AppendDataBoundItems ="true" >
                     <asp:ListItem Text ="Select" Value ="-1" />
                    </asp:DropDownList> 
                </td>
                <td>
                     <asp:RequiredFieldValidator
                    id="reqScheduleI"
                    ControlToValidate="ddlScheduleI"
                    InitialValue ="-1" 
                    Text="(Required)"
                    Runat="server" />
                </td>
                </tr>
                </table>
                  </ContentTemplate> 
                    </asp:UpdatePanel>
                <table>
                <tr>
                <td>--%>
                    <%--<asp:Button ID="Button1"   runat="server" Text="Button" />--%>
                   <%-- <asp:LinkButton ID="btnInsert" OnClick ="Insert" runat="server">Insert Movie</asp:LinkButton>
                </td>
               
                <td>
                    <asp:LinkButton ID="btnCancel" OnClick ="Cancel" CommandName="Cancel" CausesValidation ="false"  runat="server">Cancel</asp:LinkButton>
                </td>
                </tr>
            </table>
        </fieldset>--%>
            

   
     
       <asp:SqlDataSource ID="srcgrdSession" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT datesession.datesessionid, datesession.date, datesession.sessionid, 
            datesession.movieid, Movie.MovieTitle, datesession.sessiontype, datesession.scheduleid,
             Schedule.ScheduleStartDate, session2.cinema, session2.time FROM session2 INNER JOIN datesession 
             ON session2.sessionid = datesession.sessionid INNER JOIN Movie ON datesession.movieid = Movie.MovieId 
             INNER JOIN Schedule ON datesession.scheduleid = Schedule.ScheduleId INNER JOIN Cinema ON session2.cinema 
             = Cinema.CinemaId INNER JOIN TheatreStaff ON Cinema.TheatreId = TheatreStaff.TheatreId WHERE
              (TheatreStaff.TheatreStaffUserName = @username) Order By datesession.date,session2.time "
            
        DeleteCommand ="DELETE datesession WHERE datesessionid=@datesessionid " >
            
                 <SelectParameters>
                  <asp:Parameter Name ="username" Type ="string"/> 
                 </SelectParameters>
                 <DeleteParameters >
                       <asp:ControlParameter Name="datesessionid" ControlID ="grdSession" />
                 </DeleteParameters>
            </asp:SqlDataSource>
         
             <asp:SqlDataSource ID="srcSessionSelect" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT datesession.datesessionid, Schedule.ScheduleStartDate, datesession.sessionid, datesession.date, Movie.MovieTitle, datesession.movieid, datesession.sessiontype, datesession.scheduleid, session2.time, session2.cinema FROM datesession INNER JOIN Movie ON datesession.movieid = Movie.MovieId INNER JOIN session2 ON datesession.sessionid = session2.sessionid INNER JOIN Schedule ON datesession.scheduleid = Schedule.ScheduleId WHERE (datesession.datesessionid = @datesessionid)"
      
             UpdateCommand ="UPDATE datesession SET date=@date,movieid=@movieid,
        scheduleid=@scheduleid,sessionid=@sessionid
            WHERE datesessionid=@datesessionid"
            InsertCommand="INSERT INTO datesession(date,movieid,sessiontype,scheduleid,sessionid)
            VALUES (@date,@movieid,@sessiontype,@scheduleid,@sessionid)"
             runat="server">
                <SelectParameters>
                  <asp:ControlParameter Name ="datesessionid" ControlID ="grdSession"  PropertyName='SelectedDataKey("datesessionid")'  />
                  <%--<asp:ControlParameter Name="date" ControlID ="grdSession"   PropertyName='SelectedDataKey("date")'  />--%>
                </SelectParameters>
                <UpdateParameters > 
                
                  <asp:ControlParameter Name="date" ControlID ="grdSession" DbType="Date"   PropertyName='SelectedDataKey("date")'  />
                    <asp:Parameter Name="movieid" />
            
                    <asp:Parameter Name="scheduleid" />
                    <asp:Parameter Name="sessionid" />
            <%--         <asp:Parameter Name="cinema"    />--%>
                     
                  <asp:ControlParameter Name ="datesessionid"   ControlID ="grdSession"/>
                
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="date" />
                    <asp:Parameter Name="movieid" />
                    <asp:Parameter Name="sessiontype" />
                    <asp:Parameter Name="scheduleid" />
                    <asp:Parameter Name="sessionid" />
                </InsertParameters>
            </asp:SqlDataSource>
             
            <asp:SqlDataSource ID="srcType" runat="server" 
                  ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                  SelectCommand="SELECT DISTINCT sessiontype FROM datesession">
            </asp:SqlDataSource>
            
            <asp:SqlDataSource ID="srcSchedule" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT ScheduleId, ScheduleStartDate FROM Schedule WHERE TheatreId=@TheatreId">
                <SelectParameters >
                    <asp:ControlParameter Name ="TheatreId" ControlID ="lblId"/>
                </SelectParameters>
            </asp:SqlDataSource>
            
            <asp:SqlDataSource ID="srcMovie" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            
        SelectCommand="SELECT Movie.MovieTitle,Movie.MovieId,Movie.showing,Movie.showing  FROM Movie WHERE Movie.TheatreId=@TheatreId AND Movie.showing ='true' ">
                <SelectParameters >
                    <asp:ControlParameter Name ="TheatreId" ControlID ="lblId"/>
                </SelectParameters>
            </asp:SqlDataSource>
            
            <asp:SqlDataSource ID="srcSessionid" runat="server"  ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            
        SelectCommand ="SELECT DISTINCT session2.time, session2.sessionid, session2.cinema FROM session2 INNER JOIN Cinema ON session2.cinema = Cinema.CinemaId WHERE (Cinema.TheatreId = @TheatreId) AND (session2.cinema = @cinema) ORDER BY session2.time">
                <SelectParameters >
                    <asp:ControlParameter Name ="TheatreId" ControlID ="lblId"/>
                    <%--<asp:ControlParameter  Name ="cinema" ControlID ="ddlCinema" PropertyName="SelectedValue" />--%><asp:ControlParameter 
                        ControlID="Label7" Name="cinema" PropertyName="Text" />
                </SelectParameters>
            </asp:SqlDataSource>
             <%--<asp:SqlDataSource ID="srcCinema" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT DISTINCT session2.cinema FROM session2,Cinema,TheatreStaff WHERE TheatreStaff.TheatreId=Cinema.TheatreId AND Cinema.TheatreId=@TheatreId">
                <SelectParameters >
                    <asp:ControlParameter Name ="TheatreId" ControlID ="lblId"/>
                </SelectParameters>
            </asp:SqlDataSource>--%>
             <asp:SqlDataSource ID="srcCinema" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT DISTINCT CinemaId FROM Cinema WHERE TheatreId=@TheatreId">
                <SelectParameters >
                    <asp:ControlParameter Name ="TheatreId" ControlID ="lblId"/>
                </SelectParameters>
            </asp:SqlDataSource>
        
       
     
       
   
    <table align="left"  cellpadding="15" ><tr><td>Copyright@2012 MovieTix</td><td><asp:HyperLink ID="HyperLink8"  CssClass="footer" NavigateUrl="~/Default.aspx" runat="server">Homepage</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink9"  CssClass="footer" NavigateUrl="~/TheatreStaff/Session.aspx" runat="server">Session</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink10"  CssClass="footer" NavigateUrl="~/TheatreStaff/Movies.aspx" runat="server">Movies</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink12"  CssClass="footer" NavigateUrl="~/register.aspx" runat="server">Register</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink13"  CssClass="footer" NavigateUrl="~/Login.aspx" runat="server">Log In</asp:HyperLink></td></tr></table>
        </div>
    </form>
</body>
</html>